<template>
  <div>

    <el-dialog title="工厂认证审核" :visible.sync="dialogVisible" @close="closeEdit(false)" width="800px">
      <el-form :model="authForm" ref="authForm" label-width="120px" style="width: 90%;">

        <el-row :gutter="40">
          <el-col :span="24">
            <el-form-item 
              label="状态">
              <el-radio-group v-model="status">
                <el-radio :label="1">{{statusText}}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item 
              label="审核说明" 
              prop="remark"
              >
              <el-input v-model="authForm.remark" type="textarea" :rows="3"></el-input>
            </el-form-item>

            <el-form-item
              v-if="checkYes == 3"
              label="认证图片">
              <el-upload
                :action="uploadUrl"
                :file-list="imageList"
                accept="image/png, image/jpeg"
                limit="10"
                list-type="picture-card"
                :on-remove="handleRemove"
                :on-success="handleSuccess"
                :multiple="true">
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>

          </el-col>
        </el-row>

        

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="closeEdit(false)">取 消</el-button>
        <SubmitButton v-if="checkYes == 1" type="primary" size="" :ref-form="()=>{return this.$refs['authForm']}" :post-option="{url: checkIngUrl, data: authForm, callback: checkCB }">
          审核中
        </SubmitButton>
        <SubmitButton v-if="checkYes == 2" type="primary" size="" :ref-form="()=>{return this.$refs['authForm']}" :post-option="{url: checkFailUrl, data: authForm, callback: checkCB }">
          不通过
        </SubmitButton>
        <SubmitButton v-if="checkYes == 3" type="primary" size="" :ref-form="()=>{return this.$refs['authForm']}" :post-option="{url: checkPassUrl, data: authForm, callback: checkCB }">
          通 过
        </SubmitButton>
      </div>

    </el-dialog>

  </div>
  
</template>


<script>

  import SubmitButton from '../common/SubmitButton'

  import CommonApi from '../../api/CommonApi'
  import CompanyApi from '../../api/CompanyApi'
  

  export default {
    components: {
      SubmitButton
    },
    data(){
      return {
        
        status: 1,
        statusText: '',

        authForm: {
          accountId: '',
          remark: '',
          imageUrls: '',
        },

        imageList: [],

        checkPassUrl: CompanyApi.URL_CHECK_STATUS_PASS,
        checkFailUrl: CompanyApi.URL_CHECK_STATUS_FAIL,
        checkIngUrl: CompanyApi.URL_CHECK_STATUS_ING,
        uploadUrl: CommonApi.URL_UPLOAD_IMAGE,
      }
    },
    props: ['isShow', 'authObj', 'checkYes'],
    computed: {
      dialogVisible: {
        get: function(){
          return this.isShow;  
        },
        set: function(val){}
      }
    },
    watch: {
      dialogVisible: function(newVal, oldVal){
        if (newVal) {
          this.authForm.accountId = this.authObj.account_id;
          if (this.checkYes == 1) {
            this.statusText = '审核中';
          }else if (this.checkYes == 2) {
            this.statusText = '不通过';
          }else{
            this.statusText = '通 过';
          }
        }
      }
    },
    created(){
    },
    methods: {
      checkCB(json){
        this.closeEdit(true);
      },
      closeEdit(isSuccess){
        this.imageList = [];
        this.$refs['authForm'].resetFields();
        this.$root.eventHub.$emit('closeEditDialog', isSuccess);
      },
      handleRemove(file, fileList) {
        if (fileList == null || fileList.length <= 0){
          this.authForm.imageUrls = '';
          return;
        }
        let imageUrlList = '';
        for (var i = 0; i < fileList.length; i++) {
          imageUrlList = imageUrlList + '/-/' + fileList[i].response.link;
        }
        this.authForm.imageUrls = imageUrlList;


        console.log('------------');
        this.imageList = fileList;
        console.log(this.imageList);
      },
      handleSuccess(response, file, fileList) {
        let imageUrlList = '';
        for (var i = 0; i < fileList.length; i++) {
          imageUrlList = imageUrlList + '/-/' + fileList[i].response.link;
        }
        this.authForm.imageUrls = imageUrlList;
        
        console.log('++++++++++++');
        this.imageList = fileList;
        console.log(this.imageList);
      },
    }
  }
</script>

